package com.ly.lypopupwindowdemo.activity;

import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import com.ly.lypopupwindowdemo.R;

public class SecondActivity extends AppCompatActivity {

    private static final String TAG = "SecondActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);

        String gender_str = "";
        String name = getIntent().getStringExtra("name");
        int gender = getIntent().getIntExtra("gender",0);
        if (0==gender){
            gender_str = "男";
        }
        if (1==gender){
            gender_str = "女";
        }
        Log.e(TAG, "onCreate: 从MainActivity中传过来的name="+name+" , gender="+gender_str );


        Bundle mBundle = getIntent().getExtras();
        String name2 = mBundle.getString("name");
        String gender2 = mBundle.getString("gender");
        boolean isStar = mBundle.getBoolean("isStar");
        int height = mBundle.getInt("height");

        Log.e(TAG, "onCreate: 姓名="+name2+" , 性别=" +gender2 + " , 是否为Star="+  isStar + " , 身高="+height);


        TextView text = (TextView) findViewById(R.id.text);
        //接受MainActivity传过来的值，并显示再TextView中，然后告诉MainActivity我已经收到了消息。
        String str = getIntent().getStringExtra("msg1");
        Log.e(TAG, "onCreate: str1=="+str );
        text.setText(str);
        //创建一个Bundle对象，用来把数据传递到MainActivity中
        Bundle bundle = new Bundle();
        bundle.putString("msg2","收到了消息，你好，我是B");
        bundle.putString("phone","15632031701");
        final Intent intent = new Intent();
        intent.putExtras(bundle);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                setResult(RESULT_OK,intent);//setResult()方法必须在finish()之前
                finish();//此处一定要调用finish()方法
            }
        },5000);











    }


}
